﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_AddMoney : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.lbCustomerName.Text = _Customer.CustomerName;

            long ToCustomerID = Shove._Convert.StrToLong(Request["id"], -1);
            if (ToCustomerID > 0)
            {
                Customer tc = new Customer(_Site.ID);
                tc.ID = ToCustomerID;

                string ReturnDescription = "";
                int Result = tc.GetCustomerInformationByID(ref ReturnDescription);

                if (Result != 0)
                {
                    Shove._Web.JavaScript.Alert(this.Page, ReturnDescription);

                    return;
                }

                tbCustomerName.Text = tc.CustomerNO;
                tbMemo.Text = _Customer.CustomerNO + "为" + tc.CustomerNO + "充值";
            }

            this.ibSubmit.Attributes.Add("onclick", "return confirm('" + System.Web.HttpUtility.HtmlEncode("您确信输入的数据无误，并且立即充值吗？") + "');");
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        isAtFramePageLogin = true;                              //是框架页
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url        
        RequestCompetences = Competences.BuildCompetencesList(Competences.AddMoney);//页面权限

        base.OnLoad(e);
    }

    #endregion

    protected void ibSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (tbCustomerName.Text.Trim() == "")
        {
            Shove._Web.JavaScript.Alert(this.Page, "请输入用户编号。");
            return;
        }

        double Money = Shove._Convert.StrToDouble(tbMoney.Text, 0);
        if (Money == 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "请输入正确的充值金额。");

            return;
        }

        this.tbMemo.Text = _Customer.CustomerName + "为" + tbCustomerName.Text + "手动充值:" + tbMoney.Text;

        Customer tc = new Customer(_Site.ID);
        tc.CustomerNO = Shove._Convert.ToDBC(tbCustomerName.Text.Trim());

        string ReturnDescription = "";
        int Result = tc.GetCustomerInformationByNO(ref ReturnDescription);
        if (Result != 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, ReturnDescription);

            return;
        }

        Result = 0;
        ReturnDescription = "";

        tc.AddBalanceManual(_Site.ID,tc.ID, Money, this.tbMemo.Text, _Customer.ID, ref ReturnDescription);      

        //写入操作日志
        DAL.Tables.tbl_SystemLog Log = new DAL.Tables.tbl_SystemLog();

        Log.Type.Value = 2;     //1登录日志 2操作日志
        Log.ModelName.Value = "手动充值";
        Log.ActionName.Value = "充值成功";
        Log.Memo.Value = _Customer.CustomerNO + "为" + tc.CustomerNO + "手工充入" + Money.ToString() + "元";
        Log.OperatorDate.Value = DateTime.Now;
        Log.OperatorID.Value = _Customer.ID;
        Log.IP.Value = System.Web.HttpContext.Current.Request.UserHostAddress;

        Log.Insert();
        //操作日志写入完成

        Shove._Web.JavaScript.Alert(this.Page, "充值成功!!!!");
    }

    protected void ibCencel_Click(object sender, ImageClickEventArgs e)
    {
        this.tbCustomerName.Text = string.Empty;
        this.tbMoney.Text = string.Empty;
        //this.tbMemo.Text = _Customer.RealityName + "为";
    }
}